﻿<%@ Page Title="ScrumPeak.com" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
  AutoEventWireup="true" Inherits="MvcContrib.FluentHtml.ModelViewPage<Peak.Web.Controllers.Models.DashboardModel>" %>

<%@ Import Namespace="Peak.Web.Controllers.Models" %>
<%@ Import Namespace="Peak.Web.Controllers.HtmlExtentions" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="Peak.Web.Controllers" %>
<%@ Import Namespace="Peak.Core" %>
<%@ Import Namespace="Peak.Resources" %>
<asp:Content ContentPlaceHolderID="center" runat="server">
  <div class="page-title">
    <%= PageTitles.Dashboard %></div>
  <div class="page-content">
    <script type="text/javascript">
      $(document).ready(function() {
        $('.editTaskAssignedTo').editable('<%= Html.BuildUrlFromExpression<TaskController>(f=>f.EditAssignedTo(0,0)) %>', { 
          data : <% =Model.Users.SerializeToJson() %>,
          type : "select", 
          cancel : 'Cancel',
          submit : 'OK',         
          tooltip : 'Click to edit...',
          placeholder : '',
          id   : 'id',
          value : 'newvalue'         
        });      
  
        $('.editTaskRemainingEffort').editable('<%= Html.BuildUrlFromExpression<TaskController>(f=>f.EditRemainingEffort(0,null)) %>', { 
          cancel : 'Cancel',
          submit : 'OK',         
          tooltip : 'Click to edit...',
          placeholder : '',
          id   : 'id',
          value : 'newvalue'         
        });  
        
        $('.editTaskStatus').editable('<%= Html.BuildUrlFromExpression<TaskController>(f=>f.EditStatus(0,TaskStatus.ToDo)) %>', { 
          data : <% =ModelHelper.GetTaskStatuses() %>,
          type : "select", 
          cancel : 'Cancel',
          submit : 'OK',         
          tooltip : 'Click to edit...',
          placeholder : '',
          id   : 'id',
          value : 'newvalue'         
        });                           
      }); 
    </script>
    <table class="table">
      <tr>
        <th>
          <%= Labels.UserName %>
        </th>
        <th>
          <%= Labels.IsWorkingOn%>
        </th>
        <th>
          <%= Labels.WillWorkOn%>
        </th>
      </tr>
      <% foreach (UserActivityModel activity in Model.Activities)
         {%>
      <tr>
        <td width="10">
          <%= activity.User.UserName %>
        </td>
        <td>
          <% foreach (Task task in activity.CurrentTasks)
             {%>
          <%= Html.ActionLink<TaskController>(f=>f.Index(task.Id), task.Name) %><br />
          <% } %>
          <% if (activity.CurrentTasks.Count == 0)
             {%>
              <%= Labels.Nothing %>
          <% }%>
        </td>
        <td>
           <% foreach (Task task in activity.NextTasks)
             {%>
          <%= Html.ActionLink<TaskController>(f=>f.Index(task.Id), task.Name) %><br />
          <% } %>
          <% if (activity.NextTasks.Count == 0)
             {%>
             <%= Labels.Nothing %>
          <% }%>
        </td>
      </tr>      
      <% } %>
    </table>
    <br />
    <%= Html.PopupLink(Labels.Filter, "filterPopup")%>
    <%= Model.Filter.GetDescription() %>
    <br />
    <form method="post" id="search">
    <table width="100%">
      <tr>
        <td width="auto">
          <%= Html.TextBox("filter.QuickFilter",null, new { @style = "width:99%;" }) %>
        </td>
        <td width="10">
          <input style="align: left" type="submit" value="<%= Buttons.Search %>" />
        </td>
      </tr>
    </table>
    </form>
    <div id="filterPopup" class="PopupDiv">
      <form id="tasksFilterForm" method="post" class="PopupContent">
      <table>
        <tr>
          <td width="10">
            <%= this.CheckBox(f=>f.Filter.StatusToDo) %>
          </td>
          <td>
            <%= Statuses.ToDo %>
          </td>
        </tr>
        <tr>
          <td width="10">
            <%= this.CheckBox(f => f.Filter.StatusInProgress) %>
          </td>
          <td>
            <%= Statuses.InProgress %>
          </td>
        </tr>
        <tr>
          <td width="10">
            <%= this.CheckBox(f => f.Filter.StatusReadyForTest) %>
          </td>
          <td>
            <%= Statuses.ReadyForTest %>
          </td>
        </tr>
        <tr>
          <td width="10">
            <%= this.CheckBox(f => f.Filter.StatusDone) %>
          </td>
          <td>
            <%= Statuses.Done %>
          </td>
        </tr>
        <tr>
          <td width="80">
            <%= Labels.AssignedTo %>
          </td>
          <td>
            <%= this.UsersList(f => f.Filter.AssignedTo)%>
          </td>
        </tr>
        <tr>
          <td width="10">
            <%= this.CheckBox(f => f.Filter.CurrentSprintOnly) %>
          </td>
          <td>
            <%= Labels.CurrentSprintOnly %>
          </td>
        </tr>
      </table>
      <%= Html.PeakSubmitButton<DashboardController>(f => f.Index(null), Buttons.Ok, "tasksFilterForm") %>
      </form>
    </div>
    <table class="table">
      <tr>
        <th class="autoWidthColumn">
          <%= Columns.Id %>
        </th>
        <th align="left">
          <%= Columns.Name %>
        </th>
        <th>
          <%= Columns.Path %>
        </th>
        <th class="autoWidthColumn">
          <%= Columns.Status %>
        </th>
        <th class="autoWidthColumn">
          <%= Columns.AssignedTo %>
        </th>
        <th class="autoWidthColumn">
          <%= Columns.StoryPriority %>
        </th>
        <th class="autoWidthColumn">
          <%= Columns.RemainingEffort %>
        </th>
      </tr>
      <%
        foreach (DashboardItem item in Model.Items)
        {%>
      <tr>
        <td align="center">
          <%= item.Id %>
        </td>
        <td>
          <% if (item.Type == DashboardItemType.Task)
             {%>
          <%= Html.ActionLink<TaskController>(f => f.Index(item.Id), item.Name)%>
          <%= Html.Edit<TaskController>(f => f.Edit(item.Id))%>
          <%= Html.GoToStory<StoryController>(f => f.Index(item.Story.CurrentSprintStory.Id,null))%>
          <%= Html.AssignToMe<TaskController>(f => f.AssignToMe(item.Id),item.AssignedTo)%>
          <% }%>
        </td>
        <td>
          <%= item.Path %>
        </td>
        <td align="center">
          <div id="<%=item.Id %>" class="<% =ModelHelper.GetStatusClassName(item) %>">
            <%= item.Status %>
          </div>
        </td>
        <td align="center">
          <div id="<%=item.Id %>" class="editTaskAssignedTo">
            <%= Html.AssignedTo(item.AssignedTo)%>
          </div>
        </td>
        <td align="center">
          <%= item.Story.Priority %>
        </td>
        <td align="center">
          <div id="<%=item.Id %>" class="editTaskRemainingEffort">
            <%=Peak.ApplicationServices.DurationParser.ToString(item.RemainingEffort)%></div>
        </td>
      </tr>
      <%
        }%>
      <% if (Model.Items.Count == 0)
         {%>
      <tr>
        <td colspan="10">
          <%= Messages.NoResults %>
        </td>
      </tr>
      <% } %>
    </table>
  </div>
</asp:Content>
